package cn.lds.springbootmybatisplusexamplej380.service.impl;

import cn.lds.springbootmybatisplusexamplej380.dto.ResponseDTO;
import cn.lds.springbootmybatisplusexamplej380.entity.Emp;
import cn.lds.springbootmybatisplusexamplej380.mapper.EmpMapper;
import cn.lds.springbootmybatisplusexamplej380.service.EmpService;

import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class EmpServiceImpl implements EmpService {

    @Resource
    private EmpMapper empMapper;

    @Override
    public ResponseDTO<List<Emp>> selectEmpAll() {

        List<Emp> emps = empMapper.selectEmpAll();
        if (CollectionUtils.isEmpty(emps)){

        }

        return ResponseDTO.buildSuccess(emps);
    }

    @Override
    public ResponseDTO<Emp> selectEmpById(Integer id) {

        Emp emp = empMapper.selectEmpById(id);
        if (Objects.isNull(emp)){

        }

        return ResponseDTO.buildSuccess(emp);
    }

    @Override
    public ResponseDTO insertEmp(Emp emp) {

        int insert = empMapper.insert(emp);

        if (insert == 0){

        }

        return ResponseDTO.buildSuccess();
    }

    @Override
    public ResponseDTO modifyEmp(Emp emp) {
        int update = empMapper.updateById(emp);

        if (update == 0){

        }

        return ResponseDTO.buildSuccess();
    }

    @Override
    public ResponseDTO removeEmpById(Integer id) {
        int deleted = empMapper.deleteById(id);

        if (deleted == 0){

        }

        return ResponseDTO.buildSuccess();
    }
}
